import { resType, UserInfoType } from '@/utils/types'
import { request } from './request'

// 调用测试
export function getTest() {
  return request({
    url: 'crud', //此处为自己请求地址
    method: 'get',
  })
}
export function addTest(data) {
  return request({
    url: 'crud', //此处为自己请求地址
    method: 'post',
    data,
  })
}
export function updateTest(data) {
  return request({
    url: `/crud/${data.id}`,
    method: 'patch',
    data,
  })
}
export function deleteTest(data) {
  return request({
    url: `/crud/${data.id}`,
    method: 'delete',
  })
}
//每个接口都从这里封装 发出
export function addUser(data) {
  return request({
    url: 'user', //此处为自己请求地址
    method: 'post',
    data,
  })
}
export function userLogin(data) {
  return request({
    url: `user/login`,
    method: 'get',
    params:data
  })
}
export function findUserById(id) {
  return request({
    url: `user/${id}`, //此处为自己请求地址
    method: 'get',
  })
}
export function findUserByMobile(mobile) {
  return request({
    url: `user/${mobile}`, //此处为自己请求地址
    method: 'get',
  })
}

export function updateUser(data) {
  return request({
    url: `user/${data.id}`, //此处为自己请求地址
    method: 'patch',
    data: data,
  })
}

export function findAllUser() {
  return request({
    url: `user/all`, //此处为自己请求地址
    method: 'get',
  })
}
//上传文件
export function uploadFile(data) {
  return request({
    url: 'upload/album', //此处为自己请求地址
    method: 'post',
    data
  })
}

//发表文章
export function sendPost(data) {
  return request({
    url: `user/add/post`, 
    method: 'post',
    data
  })
}

//分页查询
export function findPost(data) {
  return request({
    url: `post/`, 
    method: 'get',
    params:data
  })
}
//根据id查询单个帖子
export function findOnePost(id) {
  return request({
    url: `post/${id}`, 
    method: 'get',

  })
}

//根据用户id分页查询
export function findPostByUserId(data) {
  return request({
    url: `post/ByUserId`, 
    method: 'get',
    params:data
  })
}
//根据id删除文章
export function deletePostById(id) {
  return request({
    url: `post/${id}`, 
    method: 'delete',
  })
}
// 根据idList查询
export function findPostByUserIdList(data) {
  return request({
    url: `post/ByUserIdList`, 
    method: 'get',
    params:data
  })
}
//根据圈子名称分页查询
export function findPostByTopicName(data) {
  return request({
    url: `post/ByTopicName`, 
    method: 'get',
    params:data
  })
}
//更新文章内容
export function updatePostItem(data) {
  return request({
    url: `post/item/${data.id}`, 
    method: 'patch',
    data
  })
}

//更新浏览次数和点赞功能
export function updatePostEye(data) {
  return request({
    url: `post/${data.id}`, 
    method: 'patch',
    data
  })
}

export function findOnePostById(id) {
  return request({
    url: `post/${id}`, 
    method: 'get',
  })
}

//找到单个评论联系的用户
export function findOneCommitById(id) {
  return request({
    url: `commit/${id}`, 
    method: 'get',
  })
}
//获取某篇文章的全部评论
export function findAllCommitByPostId(id) {
  return request({
    url: `post/${id}`, 
    method: 'get',
  })
}


//对某篇文章发表评论
export function sendCommit(data) {
  return request({
    url: `post/commit`, 
    method: 'post',
    data: {
      postId: data.postId,
      content: data.content,
      userId:data.userId
    }
  })
}
// 删除评论
export function deleteCommentById(id) {
  return request({
    url: `post/commit/${id}`, 
    method: 'delete',

  })
}

//获取全部圈子topic
export function getTopics() {
  return request({
    url: `topic`, 
    method: 'get',
  })
}

//创建圈子
export function createTopics(data) {
  return request({
    url: `topic`, 
    method: 'post',
    data
  })
}


//模糊搜索
export function findPostByTopicNameLike(data) {
  return request({
    url: `post/ByNameLike`, 
    method: 'get',
    params:data
  })
}
export function findUserByNameLike(data) {
  return request({
    url: `user/keywords`, 
    method: 'get',
    params:data
  })
}

export function findTopicByNameLike(data) {
  return request({
    url: `topic/keywords`, 
    method: 'get',
    params:data
  })
}

//关注功能
export function addFollows(data) {
  return request({
    url: `user/add/follows`, 
    method: 'post',
    data
  })
}

